classdef TestDotsDrawableTargets < dotsTestCase
    
    properties
        n;
        x;
        y;
        dots;
        drawManager;
        drawGroup;
    end
    
    methods
        function self = TestDotsDrawableTargets(name)
            self = self@dotsTestCase(name);
        end
        
        function setUp(self)
            self.setUp@dotsTestCase;

            dotsTheScreen.reset;
            dotsTheDrawablesManager.reset;
            self.drawManager = dotsTheDrawablesManager.theObject;
            
            self.drawGroup = 'test dots';
            self.dots = self.drawManager.newObject('dotsDrawableTargets');
            self.drawManager.addObjectToGroup(self.dots, self.drawGroup);
            self.drawManager.activateGroup(self.drawGroup);
            
            self.drawManager.openScreenWindow;
            
            self.n = 25;
            rect = self.dots.windowRect;
            hx = 0.4*rect(3)/self.dots.pixelsPerDegree;
            hy = 0.4*rect(4)/self.dots.pixelsPerDegree;
            self.x = linspace(-hx, hx, self.n);
            self.y = linspace(hy, -hy, self.n);
        end
        
        function tearDown(self)
            self.drawManager.closeScreenWindow;
            dotsTheDrawablesManager.reset;
            dotsTheScreen.reset;
            self.tearDown@dotsTestCase;
        end
        
        function testDrawDifferentThings(self)
            
            % draw no dots
            self.drawManager.mayDrawNextFrame;
            
            % don't draw invisible dots
            self.dots.isVisible = false;
            self.drawManager.mayDrawNextFrame;
            
            % draw one dot
            self.dots.x = self.x(1);
            self.dots.y = self.y(1);
            self.dots.isVisible = true;
            
            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
            
            % draw colorful, fat dot
            self.dots.x = self.x(1);
            self.dots.y = self.y(1);
            self.dots.dotSize = 10;
            self.dots.color = [255 0 0];
            
            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
            
            % draw many dots
            self.dots.x = self.x;
            self.dots.y = self.y;
            
            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
            
            % draw many dot widths
            self.dots.x = self.x;
            self.dots.y = self.y;
            self.dots.dotSize = linspace(1,10,self.n);
            
            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
            
            % draw many dot colors
            self.dots.x = self.x;
            self.dots.y = self.y;
            
            R = linspace(0, 255, self.n);
            G = linspace(128, 255, self.n);
            B = linspace(255, 0, self.n);
            A = linspace(64, 196, self.n);
            self.dots.color = cat(1, R, G, B, A);
            
            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
            
            % draw each dot shape
            self.dots.x = self.x(1:10:end);
            self.dots.y = self.y(1:10:end);
            self.dots.dotSize = 10;
            self.dots.color = [255 0 0];
            
            self.dots.shape = 0;
            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
            
            self.dots.shape = 1;
            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
            
            self.dots.shape = 2;
            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
        end
    end
end